import java.math.BigInteger;
import java.util.Scanner;

public class 爱吃素 {
    /*
    https://ac.nowcoder.com/acm/problem/227310
    看到大数乘法果断直接BigInteger, 有自带封装函数判断是否为素数, certainty是确定因子,100即可
     */
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int q = in.nextInt();
        while(q-- > 0){
            long a = in.nextLong();
            long b = in.nextLong();
            BigInteger bigInteger = new BigInteger(String.valueOf(a));
            bigInteger = bigInteger.multiply(new BigInteger(String.valueOf(b)));

            if(bigInteger.isProbablePrime(100)){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }

    }
}
